package com.oasistudio.ads.expert;

import java.util.List;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.oasistudio.ads.expert.banner.AdHistory;
import com.oasistudio.ads.expert.banner.TitleBuilder;

/** 各个联盟的横幅广告荟萃。 */
public class AdHistoryGallery extends Activity {
	AdsExpertApplication expertApp;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ad_history_gallery);
		show();
	}

	private void show() {
		for (String union : AdHistory.AdHistory.keySet()) {
			LinearLayout adContainer = (LinearLayout) findViewById(R.id.ads_history_container);
			adContainer.addView(new TitleBuilder().createTitle(this, union));

			List<Bitmap> adImages = AdHistory.AdHistory.get(union);
			for(int i=0; i<adImages.size(); i++){
				int impressionCount = AdHistory.AdHistoryCount.get(union).get(i).get();
				adContainer.addView(new TitleBuilder().createTitle(this, impressionCount));
				
				Bitmap bitmap = adImages.get(i);
				LinearLayout adHisContainer = new LinearLayout(this);
				adContainer.addView(adHisContainer);
				ImageView imageView = new ImageView(this);
				imageView.setImageBitmap(bitmap);
				adHisContainer.addView(imageView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
						LayoutParams.WRAP_CONTENT));
			}
		}
	}
	
	public void onResume(){
		super.onResume();
		LinearLayout adContainer = (LinearLayout) findViewById(R.id.ads_history_container);
		adContainer.removeAllViews();
		show();
	}
}